class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        n = len(s)
        max_length = 0
        left = 0 
        right = 0
        ans = set()
        
        while right < n:
            if s[right] not in ans:
                ans.add(s[right])
                max_length = max(max_length, len(ans))
                right += 1
            else:
                ans.remove(s[left])
                left += 1
        return max_length
        
            


a = Solution()
print(a.lengthOfLongestSubstring("abcabcbb"))

            
